package com.my.zuji.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.my.zuji.domain.bookkeeping.Account;
import com.my.zuji.domain.bookkeeping.BookingCategory;
import com.my.zuji.domain.bookkeeping.Bookkeeping;
import com.my.zuji.domain.bookkeeping.Member;
import com.my.zuji.domain.bookkeeping.Project;
import com.my.zuji.domain.bookkeeping.Seller;
import com.my.zuji.domain.bookkeeping.User;
import com.my.zuji.service.PublicService;

@Controller
@SessionAttributes("currUser")
public class BookkeepingController {
	@Autowired
	private PublicService publicService;

	@RequestMapping(value="/bookkeeping",method = RequestMethod.GET)
	public ModelAndView bookkeeping(Model model,@ModelAttribute("currUser") User user) {
		ModelAndView mv = new ModelAndView("bookkeeping");
		Map<BookingCategory,List<BookingCategory>> payoutCategory = publicService.findCategoryByName("payout");
		Map<BookingCategory,List<BookingCategory>> incomeCategory = publicService.findCategoryByName("income");
		List<Account> accountList = publicService.findAccountByUser(user);
		List<Member> memberList = publicService.findAllMemberByUser(user);
		List<Project> projectList = publicService.findProjectByUser(user);
		List<Seller> sellerList = publicService.findSellerByUser(user);
		mv.addObject("payoutCategory", payoutCategory);
		mv.addObject("incomeCategory", incomeCategory);
		mv.addObject("accountList", accountList);
		mv.addObject("memberList", memberList);
		mv.addObject("projectList", projectList);
		mv.addObject("sellerList", sellerList);
		return mv;
	}
	
	@RequestMapping(value="/income",method = RequestMethod.POST)
	@ResponseBody
	public Boolean income(@ModelAttribute("currUser") User user,Bookkeeping bookkeeping) {
		System.out.println(bookkeeping.getMember().getId());
		return false;
	}
}
